/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*	
*	Julio Montes e-mail: imc.coder@gmail.com 
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#include "sdk/include/cfgmgr.h"

#include "sdk/include/filecfg.h"
#include "sdk/include/path.h"

namespace sdk
{
    template<> ConfigManager *sdk::Mgr<ConfigManager>::instance = 0;

    ConfigManager::ConfigManager()
    {

    }

    ConfigManager::~ConfigManager()
    {
        for( std::map<wxString,sdk::FileConfig *>::iterator it = m_configFiles.begin();
            it != m_configFiles.end(); ++it )
        {
            it->second->Save();
            delete it->second;
        }
    }


    sdk::FileConfig *ConfigManager::GetFile( const wxString &filename )
    {
        const std::map<wxString,sdk::FileConfig *>::const_iterator &it = m_configFiles.find( filename );

        if( it != m_configFiles.end() )
            return it->second;

        sdk::FileConfig *l_filecfg = new sdk::FileConfig();
        l_filecfg->LoadFile( filename );

        m_configFiles[filename] = l_filecfg;

        return l_filecfg;
    }
}
